
package com.kugou.game.sdk.ui.dialog;

import com.kugou.game.sdk.utils.Rx;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;

/**
 * 对话框基类
 * 
 * @author chenys
 */
public class BaseSDKDialog extends Dialog {

    protected Context mContext;

    protected Button mOK, mCancel;

    public BaseSDKDialog(Context context) {
        this(context, 0);
    }

    public BaseSDKDialog(Context context, int theme) {
        super(context, theme);
        this.mContext = context;
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setCanceledOnTouchOutside(true);
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        mOK = (Button) findViewById(Rx.id.kg_common_dialog_btn_ok);
        if (mOK == null) {
            throw new RuntimeException(
                    "Your content must have a ImageButton whose id attribute is "
                            + "'R.id.kg_common_dialog_btn_ok'");
        }
        mCancel = (Button) findViewById(Rx.id.kg_common_dialog_btn_cancel);
        if (mCancel == null) {
            throw new RuntimeException(
                    "Your content must have a ImageButton whose id attribute is "
                            + "'R.id.kg_common_dialog_btn_cancel'");
        }
        mCancel.setOnClickListener(mCancelClickListener);
    }

    private View.OnClickListener mCancelClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    public void setOKClickListener(View.OnClickListener listener) {
        mOK.setOnClickListener(listener);
    }

    public void setCancelClickListener(View.OnClickListener listener) {
        mCancel.setOnClickListener(listener);
    }

    /**
     * 设置取消按钮名称
     */
    public void setCancelText(String str) {
        mCancel.setText(str);
    }

    /**
     * 设置ok按钮名称
     */
    public void setOKBtnText(String str) {
        mOK.setText(str);
    }

    /**
     * 设置OK按钮是否显示
     * 
     * @param visibility
     */
    public void setOKBtnVisibility(boolean visibility) {
        mOK.setVisibility(visibility ? View.VISIBLE : View.GONE);
    }

    /**
     * 设置Cancel按钮是否显示
     * 
     * @param visibility
     */
    public void setCancelBtnVisibility(boolean visibility) {
        mCancel.setVisibility(visibility ? View.VISIBLE : View.GONE);
    }
}
